package com.mud.ultimate;

import java.util.ArrayList;
import java.util.List;

import com.mud.ultimate.adapters.HighScoresAdapter;
import com.mud.ultimate.data.GameRecord;
import com.mud.ultimate.tasks.AsyncTaskDownloadHighScores;
import com.mud.ultimate.tasks.AsyncTaskDownloadHighScores.DownloadHighScoresCompleteListener;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.Toast;

public class HighScoresActivity extends Activity implements DownloadHighScoresCompleteListener{

	
	private List<GameRecord> gameRecordList;
	private ListView highScoresLW;
	private HighScoresAdapter highScoresAdapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_highscores);
		
		gameRecordList = new ArrayList<GameRecord>();
		
		highScoresLW = (ListView) findViewById(R.id.top100ScoresLW);
		highScoresAdapter = new HighScoresAdapter(this, gameRecordList);
		highScoresLW.setAdapter(highScoresAdapter);
		
		AsyncTaskDownloadHighScores task = new AsyncTaskDownloadHighScores(this, this);
		task.execute();
		
		
	}

	@Override
	public void onTaskComplete(List<GameRecord> aResult) {
		gameRecordList.clear();
		gameRecordList.addAll(aResult);
		highScoresAdapter.notifyDataSetChanged();
		
	}

	@Override
	public void onError(String aError) {
		Toast uploadOKToast = Toast.makeText(getApplicationContext(),"Error during downloading high scores!",Toast.LENGTH_SHORT);
		uploadOKToast.show();
		
	}
	
	

}
